package cn.edu.neusoft.wuguangsheng.flowerimpression.activity;

import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cn.edu.neusoft.wuguangsheng.flowerimpression.R;
import cn.edu.neusoft.wuguangsheng.flowerimpression.adapter.BaiKeAdapter;
import cn.edu.neusoft.wuguangsheng.flowerimpression.adapter.EmptyRecyclerView;
import cn.edu.neusoft.wuguangsheng.flowerimpression.bean.BaiKeBean;
import cn.edu.neusoft.wuguangsheng.flowerimpression.listener.ListListener;
import cn.edu.neusoft.wuguangsheng.flowerimpression.model.GetBaiKeListModel;

public class BaiKeListActivity extends BaseActivity {
   TextView baike_title_name;
   String title;
   ImageView baike_title_fh;
   EmptyRecyclerView baikelist_rv;
   View baikelist_ev;

   TextView tv_message;

   private List<BaiKeBean> items;

    @Override
    void initView() {
        setLayout_file(R.layout.activity_bai_ke_list);
        baike_title_name = (TextView)findViewById(R.id.baike_title_name);
        title = getIntent().getStringExtra("title");
        baike_title_name.setText(title);
        baike_title_fh = (ImageView)findViewById(R.id.baike_title_fh);
        baikelist_rv = (EmptyRecyclerView)findViewById(R.id.baikelist_rv);
        baikelist_ev = (View)findViewById(R.id.baikelist_ev);

        tv_message = (TextView)findViewById(R.id.tv_message);

        GetBaiKeListModel getBaiKeListModel = new GetBaiKeListModel();
        getBaiKeListModel.getBaiKeList(title, new ListListener<BaiKeBean>() {
            @Override
            public void onResponse(List<BaiKeBean> list) {
                LinearLayoutManager linearLayoutManager=new LinearLayoutManager(BaiKeListActivity.this);
                linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                baikelist_rv.setLayoutManager(linearLayoutManager);
                items=list;
                BaiKeAdapter baiKeAdapter=new BaiKeAdapter(BaiKeListActivity.this,items,R.layout.baike_item);
                baikelist_rv.setAdapter(baiKeAdapter);
                baikelist_rv.setItemAnimator(new DefaultItemAnimator());
                baikelist_rv.setEmptyView(baikelist_ev);
                tv_message.setText("该页面还没有百科，等待管理员添加");
            }
            @Override
            public void onFail(String msg) {

            }
        });

    }

    @Override
    void initEvent() {
        baike_title_fh.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    void initDate() {

    }
}
